package com.xiaoyu.izf.service;

import com.xiaoyu.izf.model.Region;
import com.xiaoyu.izf.model.UserAddress;
import com.xiaoyu.izf.repository.RegionDao;
import com.xiaoyu.izf.repository.UserAddressDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserAddressService {
    @Autowired
    private RegionDao regionDao;
    @Autowired
    private UserAddressDao userAddressDao;

    public List<Region> regionsByParentId(int parentId){
        return regionDao.findAllByParentId(parentId);
    }

    public UserAddress userAddressSave(UserAddress address){
        return userAddressDao.save(address);
    }

    public Region regionById(int id){
        return regionDao.findOneByRegionId(id);
    }

    public UserAddress addressOne(int id){
        return userAddressDao.findOneById(id);
    }

    public List<UserAddress> addressesByUid(int uid){
        return userAddressDao.findAllByUid(uid);
    }
}
